﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 交换两个字符的位置
void swap(char* a, char* b) {
    char temp = *a;
    *a = *b;
    *b = temp;
}

// 用于判断当前排列是否已经生成过，通过哈希思想来优化判断重复逻辑
int isDuplicated(int* hash, char* current) {
    int value = 0;
    for (int i = 0; current[i]; i++) {
        value = value * 10 + (current[i] - '0');
    }
    if (hash[value]) {
        return 1;
    }
    hash[value] = 1;
    return 0;
}

// 递归生成全排列的函数
void permute(char* str, int start, int end, int* hash, char** permutations, int* count) {
    if (start == end) {
        if (!isDuplicated(hash, str)) {
            permutations[*count] = (char*)malloc((strlen(str) + 1) * sizeof(char));
            strcpy(permutations[*count], str);
            (*count)++;
        }
    }
    else {
        for (int i = start; i <= end; i++) {
            swap(&str[start], &str[i]);
            permute(str, start + 1, end, hash, permutations, count);
            swap(&str[start], &str[i]);
        }
    }
}

int main() {
    char num[7];
    scanf("%s", num);
    int len = strlen(num);
    char** permutations = (char**)malloc(10000 * sizeof(char*));  // 假设最多10000种排列，可根据实际调整
    int* hash = (int*)malloc(1000000 * sizeof(int));  // 根据数字范围合理分配哈希表大小，这里假设最大到6位数字情况
    memset(hash, 0, 1000000 * sizeof(int));
    int count = 0;
    permute(num, 0, len - 1, hash, permutations, &count);
    for (int i = 0; i < count; i++) {
        printf("%s\n", permutations[i]);
        free(permutations[i]);
    }
    free(permutations);
    free(hash);
    return 0;
}